<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Parsing Inter Schemas</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Parsing Inter Schemas' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../intern.html">Inter Modules</a></li><li><a href="index.html">building</a></li><li><a href="index.html#2">Chapter 2: Blueprints</a></li><li><b>Parsing Inter Schemas</b></li></ul></div>
<p class="purpose">A simple API for turning textual code written in Inform 6 syntax into an inter schema.</p>

<ul class="toc"><li><a href="2-pis.html#SP1">&#167;1. Just plain code</a></li><li><a href="2-pis.html#SP2">&#167;2. Abbreviated I6S notation</a></li><li><a href="2-pis.html#SP3">&#167;3. Inline phrase definitions</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Just plain code.</b>If all we need is a schema from some code in a text, we can call this.
</p>

<p class="commentary">If the text contains syntax errors, these are attached to the schema returned;
so it's the caller's responsibility to check for those and act accordingly.
</p>

<p class="commentary">Note that the results can be tested independently of <a href="../inform7/index.html" class="internal">inform7</a> using the
<a href="../building-test/index.html" class="internal">building-test</a> unit test tool, whose tests verify that a great many I6
samples produce the correct schemas.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_schema</span><span class="plain-syntax"> *</span><span class="function-syntax">ParsingSchemas::from_text</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">ParsingSchemas::from_text</span></span>:<br/><a href="2-pis.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_provenance</span><span class="plain-syntax"> </span><span class="identifier-syntax">provenance</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-pis.html#SP5" class="function-link"><span class="function-syntax">ParsingSchemas::back_end</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">provenance</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Abbreviated I6S notation.</b>This is a slicker notation used inside the <a href="../calculus-module/index.html" class="internal">calculus</a> module for purposes
such as representing how to compile a test of a given binary predicate, or
how to store data in a given storage object. For example, <span class="extract"><span class="extract-syntax">*1.frog == *2.frog</span></span>
is a valid I6S notation, using the placeholders <span class="extract"><span class="extract-syntax">*1</span></span> and <span class="extract"><span class="extract-syntax">*2</span></span> to represent
the two terms of a binary predicate. See <a href="../calculus-module/3-cs.html" class="internal">Compilation Schemas (in calculus)</a>
for more on this notation.
</p>

<p class="commentary">Here, it's quite possible that the same piece of notation will be asked for
more than once, and we want to reply quickly, so we use a hashed dictionary
to return any already-computed answer quickly.
</p>

<p class="commentary">If the text contains syntax errors, these throw an internal error. Erroneous
I6S code can only come from within the compiler itself, and means a bug.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">dictionary</span><span class="plain-syntax"> *</span><span class="identifier-syntax">i6s_inter_schema_cache</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">inter_schema</span><span class="plain-syntax"> *</span><span class="function-syntax">ParsingSchemas::from_i6s</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">from</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_quoted_inames</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> **</span><span class="identifier-syntax">quoted_inames</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i6s_inter_schema_cache</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">i6s_inter_schema_cache</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Dictionaries::new</span><span class="plain-syntax">(512, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">dict_entry</span><span class="plain-syntax"> *</span><span class="identifier-syntax">de</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Dictionaries::find</span><span class="plain-syntax">(</span><span class="identifier-syntax">i6s_inter_schema_cache</span><span class="plain-syntax">, </span><span class="identifier-syntax">from</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">de</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="reserved-syntax">inter_schema</span><span class="plain-syntax"> *) </span><span class="identifier-syntax">Dictionaries::value_for_entry</span><span class="plain-syntax">(</span><span class="identifier-syntax">de</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">inter_schema</span><span class="plain-syntax"> *</span><span class="identifier-syntax">result</span><span class="plain-syntax"> = </span><a href="2-pis.html#SP5" class="function-link"><span class="function-syntax">ParsingSchemas::back_end</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">no_quoted_inames</span><span class="plain-syntax">, </span><span class="identifier-syntax">quoted_inames</span><span class="plain-syntax">, </span><span class="identifier-syntax">Provenance::nowhere</span><span class="plain-syntax">());</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">Dictionaries::create</span><span class="plain-syntax">(</span><span class="identifier-syntax">i6s_inter_schema_cache</span><span class="plain-syntax">, </span><span class="identifier-syntax">from</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Dictionaries::write_value</span><span class="plain-syntax">(</span><span class="identifier-syntax">i6s_inter_schema_cache</span><span class="plain-syntax">, </span><span class="identifier-syntax">from</span><span class="plain-syntax">, (</span><span class="reserved-syntax">void</span><span class="plain-syntax"> *) </span><span class="identifier-syntax">result</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><a href="2-i6se.html#SP5" class="function-link"><span class="function-syntax">I6Errors::internal_error_on_schema_errors</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">result</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">result</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Inline phrase definitions.</b>This is a typical inline phrase definition which <a href="../inform7/index.html" class="internal">inform7</a> must handle:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">To</span><span class="plain-syntax"> </span><span class="identifier-syntax">say</span><span class="plain-syntax"> (</span><span class="identifier-syntax">L</span><span class="plain-syntax"> - </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">list</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">values</span><span class="plain-syntax">) </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">brace</span><span class="plain-syntax"> </span><span class="identifier-syntax">notation</span><span class="plain-syntax">:</span>
<span class="plain-syntax">        (- </span><span class="identifier-syntax">LIST_OF_TY_Say</span><span class="plain-syntax">({-</span><span class="identifier-syntax">by</span><span class="plain-syntax">-</span><span class="identifier-syntax">reference</span><span class="plain-syntax">:</span><span class="identifier-syntax">L</span><span class="plain-syntax">}, </span><span class="constant-syntax">1</span><span class="plain-syntax">); -).</span>
</pre>
<p class="commentary">Essentially, this defines "say ... in brace notation" as meaning the schema
coming from the text <span class="extract"><span class="extract-syntax">LIST_OF_TY_Say({-by-reference:L}, 1);</span></span>.
</p>

<p class="commentary">Note that the <a href="../inform7/index.html" class="internal">inform7</a> compiler calls <a href="2-pis.html#SP4" class="internal">ParsingSchemas::from_inline_phrase_definition</a>
only once on such a definition &mdash; it would clearly be slow and wasteful to parse
it anew each time it is used. Because of that, only 100 or so calls to this function
are made in a typical run, and so speed is not critical here.
</p>

<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>That was a simple example, in that only one schema was involved: it is a
head which has no tail.
</p>

<p class="commentary">However, a few inline phrases make use of the notation <span class="extract"><span class="extract-syntax">{-block}</span></span>, which
represents a block of code &mdash; usually a loop body &mdash; and which divides the
definition into a head part, before the block, and a tail part, after. So
in general we may have to compile two schemas, not one.
</p>

<p class="commentary">The text <span class="extract"><span class="extract-syntax">from</span></span> is in a wide C string because it's coming raw from the lexer,
as the content of a <span class="extract"><span class="extract-syntax">(- ... -)</span></span> lexeme, but with the <span class="extract"><span class="extract-syntax">(-</span></span> and <span class="extract"><span class="extract-syntax">-)</span></span> removed.
</p>

<p class="commentary">If the text contains syntax errors, these are attached to the schema returned;
so it's the caller's responsibility to check for those and act accordingly.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">ParsingSchemas::from_inline_phrase_definition</span><span class="plain-syntax">(</span><span class="identifier-syntax">inchar32_t</span><span class="plain-syntax"> *</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_schema</span><span class="plain-syntax"> **</span><span class="identifier-syntax">head</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_schema</span><span class="plain-syntax"> **</span><span class="identifier-syntax">tail</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_provenance</span><span class="plain-syntax"> </span><span class="identifier-syntax">provenance</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    *</span><span class="identifier-syntax">head</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">; *</span><span class="identifier-syntax">tail</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tail_defn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-pis.html#SP4_1" class="named-paragraph-link"><span class="named-paragraph">Fetch the head and tail definitions</span><span class="named-paragraph-number">4.1</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    *</span><span class="identifier-syntax">head</span><span class="plain-syntax"> = </span><a href="2-pis.html#SP1" class="function-link"><span class="function-syntax">ParsingSchemas::from_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">provenance</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">tail_defn</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        *</span><span class="identifier-syntax">tail</span><span class="plain-syntax"> = </span><a href="2-pis.html#SP1" class="function-link"><span class="function-syntax">ParsingSchemas::from_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">tail_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">provenance</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4_1" class="paragraph-anchor"></a><b>&#167;4.1. </b>A tail will only be present if the definition contains <span class="extract"><span class="extract-syntax">{-block}</span></span>. If it
does, we then split the definition into a head and a tail, and again trim
white space from each. Note that <span class="extract"><span class="extract-syntax">{-block}</span></span> is not legal anywhere else.
</p>

<p class="commentary">For example:
</p>

<blockquote>
    <p>To repeat with a King's Court begin -- end loop:</p>
</blockquote>

<p class="commentary">could be given the definition:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> {-</span><span class="identifier-syntax">my</span><span class="plain-syntax">:</span><span class="identifier-syntax">trcount</span><span class="plain-syntax">};</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">trcount</span><span class="plain-syntax">=1; </span><span class="identifier-syntax">trcount</span><span class="plain-syntax">&lt;=3; </span><span class="identifier-syntax">trcount</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        {-</span><span class="identifier-syntax">block</span><span class="plain-syntax">}</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">pull</span><span class="plain-syntax"> </span><span class="identifier-syntax">trcount</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary">This then repeats what it's given three times, while guaranteeing that the
counter is always a local variable called <span class="extract"><span class="extract-syntax">trcount</span></span>, and that no matter how
such operations are nested, they will work. We might then write:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">To</span><span class="plain-syntax"> </span><span class="identifier-syntax">say</span><span class="plain-syntax"> </span><span class="identifier-syntax">iteration</span><span class="plain-syntax">: (- </span><span class="identifier-syntax">print</span><span class="plain-syntax"> {-</span><span class="identifier-syntax">my</span><span class="plain-syntax">:</span><span class="identifier-syntax">trcount</span><span class="plain-syntax">}; -).</span>
</pre>
<p class="commentary">and then this will work as might be hoped:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">repeat</span><span class="plain-syntax"> </span><span class="identifier-syntax">with</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">King</span><span class="plain-syntax">'</span><span class="identifier-syntax">s</span><span class="plain-syntax"> </span><span class="identifier-syntax">Court</span><span class="plain-syntax">:</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">say</span><span class="plain-syntax"> </span><span class="string-syntax">"[iteration]..."</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">repeat</span><span class="plain-syntax"> </span><span class="identifier-syntax">with</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">King</span><span class="plain-syntax">'</span><span class="identifier-syntax">s</span><span class="plain-syntax"> </span><span class="identifier-syntax">Court</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">say</span><span class="plain-syntax"> </span><span class="string-syntax">"[iteration]. You play a Shanty Town, getting +2 Actions."</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Fetch the head and tail definitions</span><span class="named-paragraph-number">4.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Characters::is_whitespace</span><span class="plain-syntax">(*</span><span class="identifier-syntax">from</span><span class="plain-syntax">)) </span><span class="identifier-syntax">from</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">, </span><span class="string-syntax">"%w"</span><span class="plain-syntax">, </span><span class="identifier-syntax">from</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">effective_end</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0, </span><span class="identifier-syntax">L</span><span class="plain-syntax">=</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">); </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">L</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (!(</span><span class="identifier-syntax">Characters::is_whitespace</span><span class="plain-syntax">(</span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">))))</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">effective_end</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">+1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Str::truncate</span><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">effective_end</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0, </span><span class="identifier-syntax">L</span><span class="plain-syntax">=</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">); </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">L</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::includes_wide_string_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">U</span><span class="string-syntax">"{-block}"</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">after</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">+8, </span><span class="identifier-syntax">before</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Characters::is_whitespace</span><span class="plain-syntax">(</span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">after</span><span class="plain-syntax">))) </span><span class="identifier-syntax">after</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Characters::is_whitespace</span><span class="plain-syntax">(</span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">before</span><span class="plain-syntax">-1))) </span><span class="identifier-syntax">before</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Str::copy_tail</span><span class="plain-syntax">(</span><span class="identifier-syntax">tail_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">after</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Str::truncate</span><span class="plain-syntax">(</span><span class="identifier-syntax">head_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">before</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-pis.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>The public API above funnels down through this more private function:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_schema</span><span class="plain-syntax"> *</span><span class="function-syntax">ParsingSchemas::back_end</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">ParsingSchemas::back_end</span></span>:<br/><a href="2-pis.html#SP1">&#167;1</a>, <a href="2-pis.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">abbreviated</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_quoted_inames</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> **</span><span class="identifier-syntax">quoted_inames</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_provenance</span><span class="plain-syntax"> </span><span class="identifier-syntax">provenance</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_schema</span><span class="plain-syntax"> *</span><span class="identifier-syntax">sch</span><span class="plain-syntax"> = </span><a href="2-is.html#SP2" class="function-link"><span class="function-syntax">InterSchemas::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="identifier-syntax">provenance</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">SCHEMA_COMPILATION_DA</span><span class="plain-syntax">)) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">SCHEMA_COMPILATION_DETAILS_DA</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"\n\n------------\nCompiling inter schema from: &lt;%S&gt;\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">from</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">pos</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">abbreviated</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Str::begins_with_wide_string</span><span class="plain-syntax">(</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="identifier-syntax">U</span><span class="string-syntax">"*=-"</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">sch</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">dereference_mode</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">; </span><span class="identifier-syntax">pos</span><span class="plain-syntax"> = </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><a href="2-tkn.html#SP1" class="function-link"><span class="function-syntax">Tokenisation::go</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">sch</span><span class="plain-syntax">, </span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">abbreviated</span><span class="plain-syntax">, </span><span class="identifier-syntax">no_quoted_inames</span><span class="plain-syntax">, </span><span class="identifier-syntax">quoted_inames</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">SCHEMA_COMPILATION_DA</span><span class="plain-syntax">)) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">SCHEMA_COMPILATION_DETAILS_DA</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Tokenised inter schema:\n$1"</span><span class="plain-syntax">, </span><span class="identifier-syntax">sch</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><a href="2-rmf.html#SP1" class="function-link"><span class="function-syntax">Ramification::go</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">sch</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-is.html#SP18" class="function-link"><span class="function-syntax">InterSchemas::lint</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">sch</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">SCHEMA_COMPILATION_DA</span><span class="plain-syntax">)) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">SCHEMA_COMPILATION_DETAILS_DA</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Completed inter schema:\n$1"</span><span class="plain-syntax">, </span><span class="identifier-syntax">sch</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">sch</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="2-is.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-bm.html">1</a></li><li class="progresscurrentchapter">2</li><li class="progresssection"><a href="2-is.html">is</a></li><li class="progresscurrent">pis</li><li class="progresssection"><a href="2-tkn.html">tkn</a></li><li class="progresssection"><a href="2-rmf.html">rmf</a></li><li class="progresssection"><a href="2-i6o.html">i6o</a></li><li class="progresssection"><a href="2-eis.html">eis</a></li><li class="progresssection"><a href="2-if.html">if</a></li><li class="progresssection"><a href="2-i6a.html">i6a</a></li><li class="progresssection"><a href="2-i6se.html">i6se</a></li><li class="progresschapter"><a href="3-prd.html">3</a></li><li class="progressnext"><a href="2-tkn.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

